package com.dongdongshop.controller;


import com.dongdongshop.data.Result;
import com.dongdongshop.service.UserService;
import com.dongdongshop.vo.UserVO;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @PostMapping("register")
    public Result register(@RequestBody UserVO userVO) {
        return userService.register(userVO);
    }

    @PostMapping("registerWeibo")
    public Result registerWeibo(@RequestBody UserVO userVO) {
        return userService.registerWeibo(userVO);
    }

    //短信验证码比较慢用户体验差
    //需要异步发送短信,用户如何校验验证码
    @PostMapping("sendPhoneMessage")
    public Result sendPhoneMessage(@RequestParam String phoneNum) {
        //调用service发送mq生产
        userService.sendPhoneMessage(phoneNum);
        /**/
        return Result.OK();
    }

    @PostMapping("getUserByName")
    public Result getUserByName(@RequestParam String userName){
        UserVO vo=   userService.getUserByName(userName);
        return Result.OK().setData(vo);
    }


    //定时器任务,发送邮件
    @XxlJob("postMail")
    public void postMail(){
        userService.postMail();
    }
}

